<?php
session_start();
if (isset($_SESSION['userid']) && $_SESSION['level']!=2)
{
	header ("location: login.php");
	exit();
}

?>
<?php
include("includes/top_user.php");
?>

<?php
include("includes/connect.php");
$id=$_GET['userid'];
if(isset($_POST['ok']))
{
	if($_POST['tb_user'] == null) { echo "Please enter your username"; }
	else{ $u = $_POST['tb_user']; }
	if($_POST['tb_pass'] != $_POST['tb_repass']) { echo "Password and Re-password is not match"; }
	else {
			if($_POST['tb_pass'] != null) { $p = $_POST['tb_pass']; }
		}
	$l = $_POST['level'];
	if($_POST['tb_name'] == null) { echo "Please enter your name"; }
	else{ $n = $_POST['tb_name']; }
	if($_POST['tb_email'] == null) { echo "Please enter your email"; }
	else{ $e = $_POST['tb_email']; }
	if($u && $p && $l && $n && $e)
	{
		$sql = "update user set username='".$u."', password='".$p."', level='".$l."', hoten='".$n."', email='".$e."' where id='".$id."'";
		mysql_query($sql);
		header("location:users.php");
		exit();
 	}
}
$sql="select * from user where id='".$id."'";
$query=mysql_query($sql);
$row=mysql_fetch_array($query);
?>
<div id="box">
<h3>Quản lý thành viên</h3>
<form class="fr_manage_user" name="fr_manage_user" action="edit_user.php?userid=<?=$id?>" method="post">
    Level : <select name="level">
            <option value="1" <? if($row['level'] == 1) echo "selected";  ?>>
            Member </option>
            <option value="2" <? if($row['level'] == 2) echo "selected"; ?>>
            Administration </option>
            </select><br />
    Username : <input type="text" name="tb_user"  size="20" value="<?=$row['username']?>"  /> <br />
    Password : <input type="password" name="tb_pass" size="20" value="<?=$row['password']?>"  /> <br />
    Re-Password : <input type="password" name="tb_repass" size="20"  /> <br />
    Họ Tên : <input type="text" name="tb_name" size="39" value="<?=$row['hoten']?>"  /> <br />
    Email : <input type="text" name="tb_email" size="40" value="<?=$row['email']?>"  /> <br />
    <input type="submit" name="ok" value="Cập Nhật"  />
        
</form>

</div><!--box-->

<?
include("includes/sidebar.php");
include("includes/footer.php");
?>

